<template>
    <div class="page-wrapper">
        <div class="page-wrapper__body">
            <div class="page-container is-form" v-loading="isLoading">
                <el-form ref="xiaoJobForm" :model="model" label-width="140px" label-position="left">
                    <div class="block-title"><i>¶</i><el-button type="default" icon="el-icon-back" round size="mini" class="more" @click="onBack">返回</el-button> 岗位招聘信息</div>
                    <div style="height:20px;"></div>
                    <el-form-item label="岗位分类: ">
                        <el-input placeholder="请输入岗位分类：" v-model="model.jobType"></el-input>
                    </el-form-item>
                    <el-form-item label="岗位名称: ">
                        <el-input placeholder="请输入岗位名称：" v-model="model.jobName"></el-input>
                    </el-form-item>
                    <el-form-item label="职位性质: ">
                        <el-input placeholder="请输入职位性质：" v-model="model.jobCategory"></el-input>
                    </el-form-item>
                    <el-form-item label="所属部门: ">
                        <el-input placeholder="请输入所属部门：" v-model="model.dept"></el-input>
                    </el-form-item>
                    <el-form-item label="工作地点: ">
                        <el-input placeholder="请输入工作地点：" v-model="model.workPlace"></el-input>
                    </el-form-item>
                    <el-form-item label="薪资: ">
                        <el-input placeholder="请输入薪资：" v-model="model.salary"></el-input>
                    </el-form-item>
                    <el-form-item label="职位说明: ">
                        <el-input type="textarea" :rows="4" placeholder="请输入职位说明：" v-model="model.jobDesc"></el-input>
                    </el-form-item>
                    <el-form-item label="岗位要求: ">
                        <el-input type="textarea" :rows="4" placeholder="请输入岗位要求：" v-model="model.requirement"></el-input>
                    </el-form-item>
                    <el-form-item label="招聘城市: ">
                        <el-input placeholder="请输入招聘城市：" v-model="model.xiaoJobCitys.city"></el-input>
                    </el-form-item>
                    <el-form-item label="招聘链接: ">
                        <el-input placeholder="请输入招聘链接：" v-model="model.xiaoJobCitys.applyUrl"></el-input>
                    </el-form-item>
                </el-form>
            </div>
        </div>
        <div class="form-footer">
            <el-button type="primary" @click="onSubmit" style="width:120px;">保存</el-button>
            <el-button @click="onBack">取 消</el-button>
        </div>
    </div>
</template>

<script>
    import {getDetail, updateOne} from "../../api/job/xiao";

    export default {
        name: "edit",
        data(){
            return{
                model:{},
                params:{
                    id:0
                },
                isLoading:false
            }
        },
        methods:{
            onBack(){
                this.$router.push('/xiao/job/list')
            },
            onSubmit(){
                this.isLoading = true;
                this.$refs['xiaoJobForm'].validate((valid) => {
                    if(valid){
                        this.handleSubmit();
                    }
                })
            },
            async handleSubmit(){
                let resp = await updateOne({entity: this.model});
                if(this.qUtil.validResp(resp)){
                    this.isLoading = false;
                    this.$message({
                        message: '修改成功！',
                        type: 'success'
                    });
                    this.onBack();
                }
                this.isLoading = false;
            },
            async loadData(){
                if(this.params.id <= 0){
                    this.$alert('参数错误', '提示', { confirmButtonText: '确定',okFn: ()=> {
                            this.onBack()
                        }});
                    return false;
                }
                this.isLoading = true;
                let resp = await getDetail(this.params.id);
                if(!this.qUtil.validResp(resp)){
                    this.isLoading = false;
                    this.$alert('请求数据失败!', '提示', { confirmButtonText: '确定',okFn: ()=> {
                            this.onBack()
                        }});
                    return false;
                }
                this.model = resp.data.model || {};
                this.isLoading = false;
            },
        },
        mounted(){
            this.params.id = parseInt(this.$route.params.id) || 0;
            this.loadData();
        }
    }
</script>

<style scoped>
    .form-text{
        margin-top:-6px;
        text-align: left;
        line-height: 30px;
        font-size:14px;
        color:#666;
    }
</style>